<?php
class StartupBehaviour extends CBehavior {

    public function events() {
        return array_merge(parent::events(), array(
            'onBeginRequest' => 'beginRequest',
        ));
    }

    public function beginRequest(CEvent $event) {

        $language = Yii::app()->request->getPreferredLanguage();
        if ($language != 'pt_pt') {

            $language = 'es';
            Yii::app()->setLanguage($language);
             Yii::app()->session['_lang']=Yii::app()->language;
        }
        /* if (isset($_POST['lang']))
               $this->owner->user->setState('applicationLanguage', $_POST['lang']);
       if ($this->owner->user->getState('applicationLanguage'))
            $this->owner->language=$this->owner->user->getState('applicationLanguage');
        else 
            $this->owner->language='en';*/
    
    }

}
?>
